<script setup lang="ts">

import { useRouter } from 'vue-router';
import { computed, onMounted } from 'vue';
import { useLocaleStore } from '@/stores/localeStore';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import en from 'element-plus/es/locale/lang/en';
import {$account} from "@yeying-community/yeying-wallet";
const router = useRouter();
const localeStore = useLocaleStore();
const locale = computed(() => {
  const currentLocale = localeStore.locale === 'zh-CN' ? zhCn : en;
  console.log('App.vue - 当前语言设置:', localeStore.locale, '使用的Element Plus语言包:', currentLocale);
  return currentLocale;
});

const changeLogin = () => {
  const isLogin = $account.checkLogin()
  if (isLogin) {
    return true
  } else {
    // 暂时注释掉路由跳转，避免跳转到不存在的路由
    // router.push("/toLogin")
    console.log('用户未登录')
  }
  return false
}

// 暂时注释掉自动登录检查
// changeLogin()

onMounted(() => {
  console.log('App.vue 挂载完成 - 当前语言:', localeStore.locale);
  console.log('localStorage中的语言:', localStorage.getItem('i18nextLng'));
})

</script>

<template>
  <el-config-provider :locale="locale">
    <router-view />
  </el-config-provider>
</template>

<style lang="scss" scoped></style>